/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.dao.hibernate;

import java.sql.SQLException;

import org.activequant.core.domainmodel.account.BrokerAccount;
import org.activequant.dao.IBrokerAccountDao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;


/**
 * BrokerAccountDao extends DaoSupportBase&lt;BrokerAccount&gt; implements IBrokerAccountDao.<br/>
 * Holds the following inherited variables:
 * <ul>
 * <li>clazz(Class&lt;BrokerAccount&gt;)</li>
 * <li>hibernateTemplate(HibernateTemplate)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 *  - [02.11.2007] Created (Erik Nijkamp)<br>
 *
 *  @author Erik Nijkamp
 */
public class BrokerAccountDao extends DaoSupportBase<BrokerAccount> implements IBrokerAccountDao {
	/**
	 * Constructs a BrokerAccountDao(extends DaoSupportBase&lt;BrokerAccount&gt; implements IBrokerAccountDao) using <code>BrokerAccount.class</code>
	 * to set its associated clazz(Class&lt;BrokerAccount&gt;).
	 */
	public BrokerAccountDao() {
		super(BrokerAccount.class);
	}
	/**
	 * Constructs a BrokerAccountDao(extends DaoSupportBase&lt;BrokerAccount&gt; implements IBrokerAccountDao) using <code>BrokerAccount.class</code>
	 * to set its associated clazz(Class&lt;BrokerAccount&gt;).<br/>
	 * The given sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize the inherited hibernateTemplate(HibernateTemplate) for it.
	 * @param sessionFactory
	 */
	public BrokerAccountDao(SessionFactory sessionFactory) {
		super(BrokerAccount.class, sessionFactory);
	}
	/**
	 * returns all BrokerAccount instances whose holder(String) matches the given name(String)
	 */
	@SuppressWarnings("unchecked")
	public BrokerAccount[] findByHolder(final String name) {
		return (BrokerAccount []) getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session) throws HibernateException, SQLException {
				Query query = session.createQuery("from " + BrokerAccount.class.getName() + " where HOLDER='" + name + "'");
				return query.list().toArray(new BrokerAccount[] {});
			}
		});
	}
}
